// V-webapp/src/api/orders.ts
import request from './request'

// 创建订单
export const createOrder = (data: {
  shipping_address: string;
  recipient_name: string;
  recipient_phone: string;
  note?: string;
  cart_ids?: number[];
}) => {
  return request.post('/orders', data);
};

// 获取订单列表
export const getMyOrders = (params?: any) => {
  return request.get('/orders/my-orders', { params });  // 注意这里也要匹配后端路由
};

// 获取订单详情
export const getOrderById = (orderId: number) => {
  return request.get(`/orders/${orderId}`);
};

// 取消订单
export const cancelOrder = (orderId: number) => {
  return request.put(`/orders/${orderId}/cancel`);
};

// 模拟支付 - 修复这里
export const processPayment = (orderId: number) => {
  return request.post(`/orders/${orderId}/pay`);  // 改为 /pay
};

// 确认收货
export const confirmOrder = (orderId: number) => {
  return request.post(`/orders/${orderId}/confirm`);
};

// 获取订单统计
export const getOrderStats = () => {
  return request.get('/orders/stats');
};

export default {
  createOrder,
  getMyOrders,
  getOrderById,
  cancelOrder,
  processPayment,
  confirmOrder,
  getOrderStats
};